package com.group.mall.service.Impl;
import com.group.mall.domain.POJO.Collect;
import com.group.mall.domain.POJO.User;
import com.group.mall.domain.VO.CollectVO;
import com.group.mall.mapper.CollectMapper;
import com.group.mall.service.CollectService;
import com.group.mall.service.UserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @Author：xiexu
 * @Date：2024/6/18 14:21
 */
@Transactional
@Service
@Slf4j
public class CollectServiceImpl implements CollectService {
    @Autowired
    CollectMapper collectMapper;
    @Autowired
    UserService userService;

    @Override
    public List<CollectVO> getCollectList(Integer userId) {
        User userInfo = userService.getUserList(userId);
        String userName = userInfo.getUsername();
        List<CollectVO> collectList1 = collectMapper.getCollectList(userId);

        for (CollectVO collectVO : collectList1) {
            collectVO.setUsername(userName);
        }
        return collectList1;
    }

    @Override
    public boolean addCollect(Collect collect) {

        return collectMapper.addCollect(collect);
    }


    @Override
    public boolean deleteCollect(Integer userId, Integer goodId) {
        return collectMapper.deleteCollect(userId, goodId);
    }
}
